package com.fxwater.admin.controller.biz;

import com.fxwater.biz.domain.GgDmInfo;
import com.fxwater.biz.service.GgDmService;
import com.fxwater.common.annotation.Log;
import com.fxwater.common.core.controller.BaseController;
import com.fxwater.common.core.domain.AjaxResult;
import com.fxwater.common.core.page.TableDataInfo;
import com.fxwater.common.enums.BusinessType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/biz/ggDm")
public class GgDmController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(PumpStationController.class);

    private String prefix = "biz/ggDm";

    @Autowired
    private GgDmService ggDmService;

    /**
     * 公共代码数据信息列表
     * @param ggDmInfo
     * @return
     */
    @RequiresPermissions("biz:ggDm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list (GgDmInfo ggDmInfo) {
        startPage();
        List<GgDmInfo> list = ggDmService.selectGgDmInfoList(ggDmInfo);
        return getDataTable(list);
    }

    /**
     * 跳转页面
     * @return
     */
    @RequiresPermissions("biz:ggDm:view")
    @GetMapping()
    public String ggDm()
    {
        logger.info("公共代码目");
        return prefix + "/ggDm";
    }

    /**
     * 查看详情
     * @return
     */
    @GetMapping("/detail/unit/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap) {
        logger.info("====进入查看详情方法,传入的公共代码id是:" + id + "====");
        GgDmInfo ggDmInfo = new GgDmInfo();
        ggDmInfo.setId(Long.parseLong(id));
        mmap.put("ggDmInfo", ggDmService.selectGgDmInfoList(ggDmInfo).get(0));
        return prefix +"/detail";
    }

    /**
     * 跳转修改页面
     * @param mmap
     * @return
     */
    @GetMapping("edit/{ggDmId}")
    public String edit ( ModelMap mmap,@PathVariable("ggDmId") String ggDmId) {
        GgDmInfo ggDmInfo = new GgDmInfo();
        ggDmInfo.setId(Long.parseLong(ggDmId));
        ggDmInfo =  ggDmService.selectGgDmInfoList(ggDmInfo).get(0);
        mmap.addAttribute("ggDmInfo", ggDmInfo);
        return prefix + "/edit";
    }

    /**
     * 保存公共代码修改信息
     * @return
     */
    @RequiresPermissions("biz:ggDm:edit")
    @Log(title = "公共代码", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult editSave(GgDmInfo ggDmInfo) {
        logger.info("公共代码" + ggDmInfo);
        return toAjax(ggDmService.editSaveGgDmInfo(ggDmInfo));
    }

    /**
     * 增加公共代码
     * @param mmap
     * @return
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        return prefix + "/add";
    }

    /**
     * 添加泵站
     * @param ggDmInfo
     * @return
     */
    @RequiresPermissions("biz:ggDm:add")
    @Log(title = "公共代码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GgDmInfo ggDmInfo)
    {
        return toAjax(ggDmService.addGgDm(ggDmInfo));
    }

    /**
     * 删除
     * @return
     */
    @RequestMapping("/remove")
    @ResponseBody
    @RequiresPermissions("biz::remove")
    @Log(title = "公共代码删除", businessType = BusinessType.DELETE)
    public AjaxResult remove(String ids) {
        return toAjax(ggDmService.removeGgdm(ids));
    }

    /**
     * 修改息状态
     * @return
     */
    @RequestMapping("/changeStatus")
    @RequiresPermissions("biz:ggDm:edit")
    @ResponseBody
    public AjaxResult changeStatus(String id,String status) {
        GgDmInfo ggDmInfo = new GgDmInfo();
        ggDmInfo.setId(Long.parseLong(id));
        ggDmInfo.setIsValid(status);
        return toAjax(ggDmService.editSaveGgDmInfo(ggDmInfo));
    }
}
